package com.arofoxmsn.runnables.test;

import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

import com.arofoxmsn.model.PhotoAlbum;
import com.arofoxmsn.model.Picture;
import com.arofoxmsn.model.User;
import com.arofoxmsn.model.UserState;
import com.arofoxmsn.model.comunication.AbstractComunicationMedia;
import com.arofoxmsn.model.comunication.Mail;
import com.arofoxmsn.model.comunication.Messenger;
import com.arofoxmsn.model.comunication.MobilePhone;
import com.arofoxmsn.model.comunication.Phone;
import com.arofoxmsn.model.comunication.SocialNetwork;
import com.arofoxmsn.model.friendship.Friendship;
import com.arofoxmsn.model.friendship.FriendshipConfiguration;
import com.arofoxmsn.model.friendship.FriendshipStateType;
import com.arofoxmsn.model.identifiedObject.FavoriteObject;
import com.arofoxmsn.model.identifiedObject.MyObject;
import com.arofoxmsn.model.invitation.AbstractInvitation;
import com.arofoxmsn.model.invitation.FriendsipInvitation;
import com.arofoxmsn.model.invitation.InvitationStateType;
import com.arofoxmsn.model.location.FavoriteLocation;
import com.arofoxmsn.model.location.Location;
import com.arofoxmsn.model.location.UserLocation;
import com.arofoxmsn.model.message.Conversation;
import com.arofoxmsn.model.message.Message;
import com.arofoxmsn.model.message.MessageStateType;
import com.arofoxmsn.model.profile.PersonalData;
import com.arofoxmsn.model.profile.Profile;
import com.arofoxmsn.model.profile.RelationshipStatus;
import com.arofoxmsn.model.profile.RelationshipStatusType;
import com.arofoxmsn.model.profile.Sex;
import com.arofoxmsn.model.publication.AbstractComment;
import com.arofoxmsn.model.publication.AbstractCommentType;
import com.arofoxmsn.model.publication.AbstractPublication;
import com.arofoxmsn.model.publication.News;
import com.arofoxmsn.model.publication.NewsComment;
import com.arofoxmsn.model.publication.PicturePublication;
import com.arofoxmsn.model.publication.ThirdPartPublication;
import com.arofoxmsn.model.userstate.AbstractUserState;
import com.arofoxmsn.model.userstate.AvaibleUserState;
import com.arofoxmsn.model.userstate.BusyUserState;
import com.arofoxmsn.model.userstate.InvisibleUserState;
import com.arofoxmsn.model.venue.AbstractVenue;
import com.arofoxmsn.model.venue.Building;
import com.arofoxmsn.model.venue.Transportation;

/**
 * this class is in charge of creating classes with hibernate
 * ORM, it will be the better way to creates
 * @author arodm
 *
 */
public class CreateClassesByHibernate {
	
	private static Class[] classesToCreate = {
		PhotoAlbum.class,
		Picture.class,
		User.class,
		UserState.class,
		AbstractComunicationMedia.class,
		Mail.class,
		Messenger.class,
		MobilePhone.class,
		Phone.class,
		SocialNetwork.class,
		Friendship.class,
		FriendshipConfiguration.class,
		FriendshipStateType.class,
		FavoriteObject.class,
		MyObject.class,
		AbstractInvitation.class,
		FriendsipInvitation.class,
		InvitationStateType.class,
		FavoriteLocation.class,
		Location.class,
		UserLocation.class,
		Conversation.class,
		Message.class,
		MessageStateType.class,
		PersonalData.class,
		Profile.class,
		RelationshipStatus.class,
		RelationshipStatusType.class,
		Sex.class,
		AbstractComment.class,
		AbstractCommentType.class,
		AbstractPublication.class,
		News.class,
		NewsComment.class,
		PicturePublication.class,
		ThirdPartPublication.class,
		AbstractUserState.class,
		AvaibleUserState.class,
		BusyUserState.class,
		InvisibleUserState.class,
		AbstractVenue.class,
		Building.class,
		Transportation.class
	};
	
	public static void main(String [] args){
		AnnotationConfiguration config = new AnnotationConfiguration();
		//Tenemos que poner todas las classes que tenemso con annotatio aca
		for(Class oneClass : classesToCreate){
			config.addAnnotatedClass(oneClass);
		}
		
		//esta linea lo que hace es utilizar la configuracion del archivo xml 
		//de configuracion de hibernate
		config.configure();
		//tambien podemos indicar cual es el archivo de configuracion
		//config.configure("hibernate.cfg.xml");
		
		//ahora tenemos que crear la tabla
		new SchemaExport(config).create(true, true);
		//el parametro script true quiere decir que hibernate lo va a crear
		//el segudno parametro export quiere decir que el script creado se ejecutara a la base de datos
		
		//Ahora vamos a tratar de incertar un registro
		
		
//		//creamos la session de transaccion.
//		SessionFactory factoria = config.buildSessionFactory();
//		//obtenemos la configuracion de session
//		Session session = factoria.getCurrentSession();
//		//iniciamos la transaccion
//		session.beginTransaction();
//		
//		Employee employee = new Employee();
//		employee.setEmpId(100);
//		employee.setEmpName("Ariel Diaz Molina");
//		
//		//le pasamos el parametro a la session
//		session.save(employee);
//		//aca es donde se ejecuta
//		session.getTransaction().commit();

	}
}
